package util

import (
	"github.com/google/uuid"
	"math/rand"
	"strings"
	"time"
)
const(
	collectionStartLetter = 26
)
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

//生成指定长度的uuid

// GetUUID 生成v4版本的uuid--36位
func GetUUID() string {
	uid := uuid.New()
	key := uid.String()
	return key
}
func GetUUID32() string {
	return GetCollectionIndexFromUUID()
}

// GetUUIDNotCrossbar 生成v4版本的uuid--32位
func GetUUIDNotCrossbar() string {
	uid := GetUUID()
	uid = strings.Replace(uid, "-", "", -1)
	return uid
}

func GetCollectionIndexFromUUID() string {
	key := GetUUIDNotCrossbar()
	//collectionIndex必须以字母开头
	rand.Seed(time.Now().UnixNano())
	index := rand.Intn(len(letters) - 1)
	firstAlphabet := letters[index]
	uid := CombineTwoString(string(firstAlphabet), key[1:])
	return uid
}